<template>
  <el-card shadow="never">
    <el-button class="mb20" @click="$router.push({ name: 'assetsInfo' })">返回</el-button>
    <el-tabs v-model="active">
      <el-tab-pane label="资产信息" name="first">
        <info ref="info" @refresh="handleRefresh" />
      </el-tab-pane>
      <el-tab-pane label="盘点记录" name="second">
        <record ref="record" />
      </el-tab-pane>
      <el-tab-pane label="历史照片" name="third">
        <history-image ref="historyImage" />
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import { getCategoryInfo } from '@/api/assetsNew'
import Info from './Info'
import Record from './Record'
import HistoryImage from './HistoryImage'
import { getSession, setSession } from '@/utils/util'

export default {
  components: {
    Info,
    Record,
    HistoryImage
  },
  data() {
    return {
      active: 'first',
      infoDetailRow: this.$route.params.row || getSession('infoDetailRow')
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async handleRefresh() {
      const res = await getCategoryInfo(this.infoDetailRow.assetsId)
      if (res.state === '000000') {
        this.$nextTick(() => {
          this.$refs.info.edit(res.data)
          this.$refs.record.edit(res.data)
          this.$refs.historyImage.edit(res.data)
        })
      }
    },
    getData() {
      const infoDetailRow = this.$route.params.row
      if (infoDetailRow) {
        setSession('infoDetailRow', infoDetailRow)
      }
      console.log('infoDetailRow', this.infoDetailRow)
      this.$nextTick(() => {
        this.$refs.info.edit(this.infoDetailRow)
        this.$refs.record.edit(this.infoDetailRow)
        this.$refs.historyImage.edit(this.infoDetailRow)
      })
    }
  }
}
</script>
